<!DOCTYPE html>
<html lang="en">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="My Personal Website For Blog">
  <meta name="author" content="黄宇辉">
  <meta name="keywords" content="learning note,hexo blog">
  <title>一个基础的SpringBoot整合Shiro案例 - 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/vs2015.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">

<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>ANONYMOUS</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                Home
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                Archives
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                Tags
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                About
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2019-08-07 12:14">
      August 7, 2019 pm
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.3k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      17
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
            <article class="markdown-body">
              <h2 id="学习笔记-一个基础的SpringBoot整合Shiro案例"><a href="#学习笔记-一个基础的SpringBoot整合Shiro案例" class="headerlink" title="学习笔记 : 一个基础的SpringBoot整合Shiro案例"></a>学习笔记 : 一个基础的SpringBoot整合Shiro案例</h2><p><em>前些日子写了一个<a href="https://github.com/YUbuntu0109/Shiro-learning/tree/master/basic%20web%20project%20with%20shiro" target="_blank" rel="noopener">整合Shiro的基本Web案例</a>,然后又进阶地学习了SpringBoot整合Shiro的基本知识,继而今天总结一下 : 写一个基础的SpringBoot整合Shiro案例~ 该案例的代码仓库 : <a href="https://github.com/YUbuntu0109/Shiro-learning/tree/master/spring%20boot%20project%20with%20shiro" target="_blank" rel="noopener">https://github.com/YUbuntu0109/Shiro-learning/tree/master/spring%20boot%20project%20with%20shiro</a></em></p>
<h3 id="数据库设计"><a href="#数据库设计" class="headerlink" title="数据库设计"></a>数据库设计</h3><p><em>数据库ER图如下所示 :</em><br><img src="/2019/08/07/%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%A1%80%E7%9A%84SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%88%E4%BE%8B/shiro-learning-database-er.png" srcset="/img/loading.gif" alt></p>
<p><em>数据表中用户及其分配的权限信息如下所示 :</em></p>
<table>
<thead>
<tr>
<th align="center">账户</th>
<th align="center">密码(MD5加密前)</th>
<th align="center">角色</th>
<th align="center">权限</th>
</tr>
</thead>
<tbody><tr>
<td align="center">admin</td>
<td align="center">demo</td>
<td align="center">admin</td>
<td align="center">*</td>
</tr>
<tr>
<td align="center">tea</td>
<td align="center">demo</td>
<td align="center">teacher</td>
<td align="center">teaListView:view , stuListView:view , stuListView:add , stuListView:edit</td>
</tr>
<tr>
<td align="center">stu</td>
<td align="center">demo</td>
<td align="center">student</td>
<td align="center">stuListView:view</td>
</tr>
</tbody></table>
<h3 id="资源权限设计"><a href="#资源权限设计" class="headerlink" title="资源权限设计"></a>资源权限设计</h3><p><em>springboot-shiro/src/main/java/pers/huangyuhui/ss/shiro/ShiroConfig.java : 资源过滤及其权限的配置信息如下</em></p>
<div class="hljs"><pre><code class="hljs java">
<span class="hljs-comment">/**
 * <span class="hljs-doctag">@description</span>: 配置过滤器
 * <span class="hljs-doctag">@param</span>: securityManager
 * <span class="hljs-doctag">@date</span>: 2019-08-05 7:59 AM
 * <span class="hljs-doctag">@return</span>: org.apache.shiro.spring.web.ShiroFilterFactoryBean
 */</span>
<span class="hljs-meta">@Bean</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> ShiroFilterFactoryBean <span class="hljs-title">shiroFilterFactoryBean</span><span class="hljs-params">(SecurityManager securityManager)</span> </span>&#123;
    ShiroFilterFactoryBean shiroFilterFactoryBean = <span class="hljs-keyword">new</span> ShiroFilterFactoryBean();
    <span class="hljs-comment">//设置安全管理器</span>
    shiroFilterFactoryBean.setSecurityManager(securityManager);
    <span class="hljs-comment">//设置自定义过滤器</span>
    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap());
    <span class="hljs-comment">//设置用户登录页,默认: http://localhost:8080/login.jsp</span>
    shiroFilterFactoryBean.setLoginUrl(<span class="hljs-string">"/loginView"</span>);
    <span class="hljs-comment">//设置用户未授权操作提示页</span>
    shiroFilterFactoryBean.setUnauthorizedUrl(<span class="hljs-string">"/unauthorizedView"</span>);
    <span class="hljs-keyword">return</span> shiroFilterFactoryBean;
&#125;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@description</span>: 设置资源的权限控制
 * <span class="hljs-doctag">@date</span>: 2019-08-05 8:31 AM
 * <span class="hljs-doctag">@return</span>: java.util.Map
 */</span>
<span class="hljs-function"><span class="hljs-keyword">private</span> Map&lt;String, String&gt; <span class="hljs-title">filterChainDefinitionMap</span><span class="hljs-params">()</span> </span>&#123;
    Map&lt;String, String&gt; filterMap = <span class="hljs-keyword">new</span> LinkedHashMap&lt;&gt;();
    <span class="hljs-comment">//需身份认证</span>
    filterMap.put(<span class="hljs-string">"/stuListView"</span>, <span class="hljs-string">"authc"</span>);
    filterMap.put(<span class="hljs-string">"/teaListView"</span>, <span class="hljs-string">"authc"</span>);
    <span class="hljs-comment">//无需身份认证:防止验证用户登录信息操作被'filterMap.put("/**", "authc")'拦截</span>
    filterMap.put(<span class="hljs-string">"/login"</span>, <span class="hljs-string">"anon"</span>);
    <span class="hljs-comment">//注销过滤器:其具体的注销逻辑代码Shiro已经替我们实现了哟</span>
    filterMap.put(<span class="hljs-string">"/logout"</span>, <span class="hljs-string">"logout"</span>);
    <span class="hljs-comment">//角色过滤:需要用户拥有'admin'角色</span>
    filterMap.put(<span class="hljs-string">"/teaListView"</span>, <span class="hljs-string">"roles[admin]"</span>);
    <span class="hljs-comment">//权限过滤:除身份认证外,还需要用户拥有对stuListView资源的view权限</span>
    filterMap.put(<span class="hljs-string">"/stuListView"</span>, <span class="hljs-string">"perms[stuListView:view]"</span>);
    filterMap.put(<span class="hljs-string">"/teaListView"</span>, <span class="hljs-string">"perms[teaListView:view]"</span>);
    <span class="hljs-comment">//拦截需要登录(用户认证)方可访问的资源(一般将/**放在最下边,不然会导致所有url都被拦截哟)</span>
    filterMap.put(<span class="hljs-string">"/**"</span>, <span class="hljs-string">"authc"</span>);
    <span class="hljs-keyword">return</span> filterMap;
&#125;

<span class="hljs-comment">// ······</span></code></pre></div>


<h3 id="凭证加密设计"><a href="#凭证加密设计" class="headerlink" title="凭证加密设计"></a>凭证加密设计</h3><p><em>springboot-shiro/src/main/java/pers/huangyuhui/ss/shiro/ShiroConfig.java : 用户凭证加密的配置信息如下(盐值:用户名)</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-comment">/**
 * <span class="hljs-doctag">@description</span>: 初始化自定义Realm
 * <span class="hljs-doctag">@param</span>: credentialsMatcher
 * <span class="hljs-doctag">@date</span>: 2019-08-05 7:50 AM
 * <span class="hljs-doctag">@return</span>: pers.huangyuhui.ss.shiro.UserRealm
 */</span>
<span class="hljs-meta">@Bean</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> UserRealm <span class="hljs-title">userRealm</span><span class="hljs-params">(HashedCredentialsMatcher hashedCredentialsMatcher)</span> </span>&#123;
    UserRealm userRealm = <span class="hljs-keyword">new</span> UserRealm();
    <span class="hljs-comment">//设置凭证匹配器</span>
    userRealm.setCredentialsMatcher(hashedCredentialsMatcher);
    <span class="hljs-keyword">return</span> userRealm;
&#125;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@description</span>: 哈希密码匹配器:比较用户登录时输入的密码,跟数据库密码配合盐值salt解密后是否一致
 * <span class="hljs-doctag">@date</span>: 2019-08-05 9:01 PM
 * <span class="hljs-doctag">@return</span>: org.apache.shiro.authc.credential.HashedCredentialsMatcher
 */</span>
<span class="hljs-meta">@Bean</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> HashedCredentialsMatcher <span class="hljs-title">hashedCredentialsMatcher</span><span class="hljs-params">()</span> </span>&#123;
    HashedCredentialsMatcher hashedCredentialsMatcher = <span class="hljs-keyword">new</span> HashedCredentialsMatcher();
    hashedCredentialsMatcher.setHashAlgorithmName(<span class="hljs-string">"md5"</span>); <span class="hljs-comment">//散列算法</span>
    hashedCredentialsMatcher.setHashIterations(<span class="hljs-number">3</span>); <span class="hljs-comment">//散列的次数</span>
    hashedCredentialsMatcher.setStoredCredentialsHexEncoded(<span class="hljs-keyword">true</span>); <span class="hljs-comment">//默认是true:Hex编码.false:Base64编码</span>
    <span class="hljs-keyword">return</span> hashedCredentialsMatcher;
&#125;

<span class="hljs-comment">// ······</span></code></pre></div>

<p><em>springboot-shiro/src/main/java/pers/huangyuhui/ss/utils/SecurityUtils.java : 密码加密逻辑如下</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-comment">/**
 * <span class="hljs-doctag">@project</span>: springboot-shiro
 * <span class="hljs-doctag">@description</span>: 加密工具
 * <span class="hljs-doctag">@author</span>: 黄宇辉
 * <span class="hljs-doctag">@date</span>: 8/5/2019-9:09 PM
 * <span class="hljs-doctag">@version</span>: 1.0
 * <span class="hljs-doctag">@website</span>: https://yubuntu0109.github.io/
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SecurityUtils</span> </span>&#123;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;
        <span class="hljs-comment">//admin-pwd [source:demo+salt:admin+hashIterations:3] :  257e3b15d67a9127d230175e43118e40</span>
        <span class="hljs-comment">//tea-pwd [source:demo+salt:tea+hashIterations:3] : f97ccdcf125073d5f19bd3de0b67eb40</span>
        <span class="hljs-comment">//stu-pwd [source:demo+salt:stu+hashIterations:3] : e1a1c9a1340d179077086b5dbee621b4</span>
        String md5Pwd = <span class="hljs-keyword">new</span> SimpleHash(<span class="hljs-string">"md5"</span>, <span class="hljs-string">"demo"</span>, ByteSource.Util.bytes(<span class="hljs-string">"stu"</span>), <span class="hljs-number">3</span>).toHex();
        System.out.println(md5Pwd);
    &#125;
&#125;</code></pre></div>


<h3 id="Thymeleaf整合Shiro标签"><a href="#Thymeleaf整合Shiro标签" class="headerlink" title="Thymeleaf整合Shiro标签"></a>Thymeleaf整合Shiro标签</h3><p><em>springboot-shiro/src/main/java/pers/huangyuhui/ss/shiro/ShiroConfig.java : Thymeleaf整合Shiro标签的配置如下</em></p>
<div class="hljs"><pre><code class="hljs java">    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@description</span>: 配置ShiroDialect, 用于thymeleaf和shiro标签配合使用
     * <span class="hljs-doctag">@date</span>: 2019-08-05 6:37 PM
     * <span class="hljs-doctag">@return</span>: at.pollux.thymeleaf.shiro.dialect.ShiroDialect
     */</span>
    <span class="hljs-meta">@Bean</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> ShiroDialect <span class="hljs-title">shiroDialect</span><span class="hljs-params">()</span> </span>&#123;
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> ShiroDialect();
&#125;</code></pre></div>


<h3 id="Shiro集成EhCache缓存"><a href="#Shiro集成EhCache缓存" class="headerlink" title="Shiro集成EhCache缓存"></a>Shiro集成EhCache缓存</h3><p><em>springboot-shiro/src/main/java/pers/huangyuhui/ss/shiro/ShiroConfig.java : Shiro集成EhCache的配置信息如下</em></p>
<div class="hljs"><pre><code class="hljs java">    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@description</span>: 安全事务管理器
     * <span class="hljs-doctag">@param</span>: credentialsMatcher
     * <span class="hljs-doctag">@date</span>: 2019-08-05 7:53 AM
     * <span class="hljs-doctag">@return</span>: org.apache.shiro.web.mgt.DefaultWebSecurityManager
     */</span>
    <span class="hljs-meta">@Bean</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> SecurityManager <span class="hljs-title">securityManager</span><span class="hljs-params">(UserRealm userRealm, EhCacheManager ehCacheManager)</span> </span>&#123;
        DefaultWebSecurityManager defaultWebSecurityManager = <span class="hljs-keyword">new</span> DefaultWebSecurityManager();
        <span class="hljs-comment">//关联自定义realm</span>
        defaultWebSecurityManager.setRealm(userRealm);
        <span class="hljs-comment">//关联缓存管理</span>
        defaultWebSecurityManager.setCacheManager(ehCacheManager);
        <span class="hljs-keyword">return</span> defaultWebSecurityManager;
    &#125;

    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@description</span>: 设置缓存管理, 缓存用户及其权限信息
     * <span class="hljs-doctag">@date</span>: 2019-08-07 7:51 AM
     * <span class="hljs-doctag">@return</span>: org.apache.shiro.cache.ehcache.EhCacheManager
     */</span>
    <span class="hljs-meta">@Bean</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> EhCacheManager <span class="hljs-title">ehCacheManager</span><span class="hljs-params">()</span> </span>&#123;
        <span class="hljs-comment">//注意:myEhcache对应ehcache-shiro.xml中的'&lt;ehcache name="myEhcache"&gt;'</span>
        CacheManager cacheManager = CacheManager.getCacheManager(<span class="hljs-string">"myEhcache"</span>);
        <span class="hljs-keyword">if</span> (cacheManager == <span class="hljs-keyword">null</span>) &#123;
            cacheManager = CacheManager.create();
        &#125;
        EhCacheManager ehCacheManager = <span class="hljs-keyword">new</span> EhCacheManager();
        ehCacheManager.setCacheManager(cacheManager);
        <span class="hljs-keyword">return</span> ehCacheManager;

    <span class="hljs-comment">// ······</span>
&#125;</code></pre></div>


<h3 id="案例截屏解析"><a href="#案例截屏解析" class="headerlink" title="案例截屏解析"></a>案例截屏解析</h3><p><em>用户登录页,访问资源前必须先进行用户身份认证,详情参考资源拦截器中的配置信息哟</em><br><img src="/2019/08/07/%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%A1%80%E7%9A%84SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%88%E4%BE%8B/springboot-shiro-%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%E9%A1%B5.PNG" srcset="/img/loading.gif" alt></p>
<p><em>若要访问教师 / 学生信息管理页,需要用户拥有<code>teaListView:view / stuListView:view</code>权限</em><br><img src="/2019/08/07/%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%A1%80%E7%9A%84SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%88%E4%BE%8B/springboot-shiro-%E7%94%A8%E6%88%B7%E4%B8%BB%E9%A1%B5.PNG" srcset="/img/loading.gif" alt></p>
<p><em>管理员( admin )拥有访问资源的所有权限( * ),所以可以操控学生信息页面中的任何操作</em><br><img src="/2019/08/07/%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%A1%80%E7%9A%84SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%88%E4%BE%8B/springboot-shiro-%5Badmin%5D-%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E9%A1%B5.PNG" srcset="/img/loading.gif" alt></p>
<p><em>管理员( admin )拥有访问资源的所有权限( * ),所以可以操控教师信息页面中的任何操作</em><br><img src="/2019/08/07/%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%A1%80%E7%9A%84SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%88%E4%BE%8B/springboot-shiro-%5Badmin%5D-%E6%95%99%E5%B8%88%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E9%A1%B5.PNG" srcset="/img/loading.gif" alt></p>
<p><em>教师( tea )拥有学生页面的<code>stuListView:view , stuListView:add , stuListView:edit</code>权限,所以删除信息操作为不可见</em><br><img src="/2019/08/07/%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%A1%80%E7%9A%84SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%88%E4%BE%8B/springboot-shiro-%5Btea%5D-%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E9%A1%B5.PNG" srcset="/img/loading.gif" alt></p>
<p><em>教师( tea )仅拥有教师信息管理页面的<code>teaListView:view</code>权限,所以增,删,改,操作为不可见状态</em><br><img src="/2019/08/07/%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%A1%80%E7%9A%84SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%88%E4%BE%8B/springboot-shiro-%5Btea%5D-%E6%95%99%E5%B8%88%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E9%A1%B5.PNG" srcset="/img/loading.gif" alt></p>
<p><em>学生( stu )仅拥有学生信息管理页面的<code>stuListView:view</code>权限,所以增,删,改,操作为不可见状态</em><br><img src="/2019/08/07/%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%A1%80%E7%9A%84SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%88%E4%BE%8B/springboot-shiro-%5Bstu%5D-%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E9%A1%B5.PNG" srcset="/img/loading.gif" alt></p>
<p><em>学生( stu )没有访问教师信息管理页面的权限,所以被资源拦截器所拦截继而进入指定的’unauthorized.html’页面</em><br><img src="/2019/08/07/%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%A1%80%E7%9A%84SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%88%E4%BE%8B/springboot-shiro-%5Bstu%5D-%E6%95%99%E5%B8%88%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E9%A1%B5.PNG" srcset="/img/loading.gif" alt></p>
<p><em>数据库设计参考了(非常感谢) : <a href="https://www.jianshu.com/p/7716951f4d7f" target="_blank" rel="noopener">https://www.jianshu.com/p/7716951f4d7f</a></em></p>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Shiro/">Shiro</a>
                    
                      <a class="hover-with-bg" href="/tags/Thymeleaf/">Thymeleaf</a>
                    
                      <a class="hover-with-bg" href="/tags/SpringBoot/">SpringBoot</a>
                    
                      <a class="hover-with-bg" href="/tags/EhCache/">EhCache</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2019/08/08/%E4%B8%BAGitHub%E9%87%8F%E8%BA%AB%E5%AE%9A%E5%88%B6%E7%9A%84%E6%B5%8F%E8%A7%88%E5%99%A8%E6%8F%92%E4%BB%B6/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">为GitHub量身定制的浏览器插件</span>
                        <span class="visible-mobile">Previous</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2019/08/07/%E8%AF%A6%E8%A7%A3Shiro%E7%9A%84%E7%BC%93%E5%AD%98%E6%9C%BA%E5%88%B6/">
                        <span class="hidden-mobile">详解Shiro的缓存机制</span>
                        <span class="visible-mobile">Next</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;TOC</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">Search</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">keyword</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "一个基础的SpringBoot整合Shiro案例&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  














</body>
</html>
